package com.stx.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.stx.dao.CeDao;
import com.stx.domain.Absent;
import com.stx.domain.Student;

@Repository
public class CeDaoImpl implements CeDao {
	/*@Resource
	private Absent ab;*/
	@Resource
	private JdbcTemplate jt;

	public List<Absent> selectAbsentRecord() {
		String sql = "select * from ce ";
		Object[] obj = null;
		List<Absent> list = jt.query(sql, obj, new rowMapper());
		return list;
	}
	
	public List selectAbsentByNo(int no){
		return jt.query("select * from ce where no="+no+"", new rowMapper());
		
	}
	
	public int absentConfirm(Absent absent){
		return jt.update("insert into  ce   values('"+absent.getId()+"','"+absent.getTime()+"','"+absent.getNo()+"','"+absent.getName()+"','"+absent.getMajor()+"','"+absent.getThing()+"','"+absent.getD()+"','"+absent.getT()+"')");
	}

	class rowMapper implements RowMapper {
		@Override
		public Object mapRow(ResultSet rs, int arg1) throws SQLException {
			Absent absent = new Absent();
			absent.setId(rs.getInt("id"));
			absent.setNo(rs.getInt("no"));
			absent.setName(rs.getString("name"));
			absent.setMajor(rs.getString("major"));
			absent.setD(rs.getString("d"));
			absent.setTime(rs.getString("time"));
			absent.setThing(rs.getString("thing"));
			absent.setT(rs.getString("t"));
			return absent;
		}
	}
}
